package com.portal.cwegportal.controller;

import com.appcenter.jz.Logger.BusinessLogger;
import com.appcenter.jz.Logger.LoggerGenre;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import com.portal.cwegportal.input.userimpmaccount.CreateUserImPmAccountInput;
import com.portal.cwegportal.input.userimpmaccount.GetUserImPmAccountInput;
import com.portal.cwegportal.service.UserImPmAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/portal/userimpmaccount")
@Api(description = "用户建管、投资信息API")
public class UserImPmAccountController {
    @Autowired
    UserImPmAccountService userImPmAccountServices;
    //UserMailAccountService userImPmAccountServices;
    @ApiOperation(value = "维护用户建管投资账户信息", notes = "维护用户建管投资账户信息",produces = "application/json")
    @PostMapping("/createImPmAccount")
    public ResponseEntity<JsonResult> createUserImPmAccount(@RequestBody CreateUserImPmAccountInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"维护用户建管投资账户信息",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(userImPmAccountServices.createUserImPmAccount(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "获取用户建管投资账户信息", notes = "获取用户建管投资账户信息",produces = "application/json")
    @PostMapping("/getUserImPmAccount")
    public ResponseEntity<JsonResult> getUserImPmAccount(@RequestBody GetUserImPmAccountInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"获取用户建管投资账户信息",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(userImPmAccountServices.getImPmAccountByTypeKey(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

}
